package NC;

public class NC33 {
    public ListNode mergeTwoLists (ListNode l1, ListNode l2) {
        ListNode ans = new ListNode(0);
        ListNode temp = ans;
        while(l1!=null&&l2!=null){
            if(l1.val>l2.val){
                temp.next = l2;
                temp = l2;
                l2 = l2.next;
            }else {
                temp.next = l1;
                temp  = l1;
                l1 = l1.next;
            }
        }
        if(l1!=null){
            temp.next = l1;
        }
        if(l2!=null){
            temp.next = l2;
        }
        return ans.next;
    }
}
